package AddHelp::CMS;
use strict;
use warnings;
use base qw( MT::Plugin );

sub get_configs {
    my ($ctx_blog) = @_;
    my $blog_id = ref($ctx_blog) ? $ctx_blog->id : $ctx_blog;
    my $p = MT->component('AddHelp');
    my $configs = {blog=>{},sys=>{}};
    $p->load_config($configs->{blog},'blog:' . $blog_id);
    $p->load_config($configs->{sys},'system');
    return $configs;
}

sub select_config {
    my ($configs,$key) = @_;
    if( defined($configs->{blog}{$key}) && $configs->{blog}{$key} ne '' ) {
        return $configs->{blog}{$key};
    }
    if( defined($configs->{sys}{$key}) ) {
        return $configs->{sys}{$key};
    }
    return '';
}

sub load_help_content {
    my $app = shift;
    my $blog_id = $app->param('blog_id');
    
    my $conf = get_configs($blog_id);
    my $help_title = select_config($conf,'addhelp_title');
    my $help_content = select_config($conf,'addhelp_content');
    
    my %param;
    $param{help_title} = $help_title;
    $param{help_content} = $help_content;
    
    return $app->load_tmpl('user_help.tmpl', \%param);
}

1;